--
-- Author: shunguo.chen
-- Date: 2016-06-21 16:49:56
--
-- IMEmojiRender

local ClassRef = app.mvc.createRenderClass(...)

-- data = 
function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node:clone())
	sprite:init(data)
	return sprite
end

function ClassRef.create(node)
	local sprite = ClassRef.extend(node:clone())
	sprite:init()
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)
	-- print("IMEmojiRender init()")

	self:setAnchorPoint(cc.p(0.5, 0.5))
	self:setTouchEnabled(true)

	display.uiAddClick(self, function()
			-- print("IMEmojiRender click")
			AM.playClickItemSound()
			executeFunc(self._onClick, self)
		end, true)

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		self:setIcon(self._data.icon)
	end
end

function ClassRef:setIcon(res)
	self._ui.Img:loadTexture(res)
end

function ClassRef:setClickHandler(func)
	self._onClick = func
end

return ClassRef